
#!/bin/bash

path=$(dirname $0)

cd $path

podSpecName=`ls |grep ".xcodeproj$"|sed "s/\.xcodeproj//g"`
echo $podSpecName

  
FRAMEWORK_NAME=$podSpecName


PROJECT_NAME=$FRAMEWORK_NAME


BUILD_DIR="."
CONFIGURATION="Release"

  
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"  
  
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"  
  
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"  
  
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"  
  
xcodebuild -project ${PROJECT_NAME}.xcodeproj -sdk iphonesimulator -arch i386 -arch x86_64 -target ${FRAMEWORK_NAME} -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator | echo  
  
xcodebuild -project ${PROJECT_NAME}.xcodeproj -sdk iphoneos -arch arm64 -arch armv7 -arch armv7s -target ${FRAMEWORK_NAME} -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos | echo  
  
rm -rf "${UNIVERSAL_LIBRARY_DIR}"  
  
mkdir "${UNIVERSAL_LIBRARY_DIR}"  
  
mkdir "${FRAMEWORK}"  
  
cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"  
  
lipo "${SIMULATOR_LIBRARY_PATH}/${FRAMEWORK_NAME}" "${DEVICE_LIBRARY_PATH}/${FRAMEWORK_NAME}" -create -output "${FRAMEWORK}/${FRAMEWORK_NAME}" | echo  

echo $FRAMEWORK

cp -rf $FRAMEWORK "./${FRAMEWORK_NAME}.framework"
# open "${FRAMEWORK}"  
